<?php

namespace frontend\modules\app\controllers;

use Yii;
use frontend\components\Controller;
use frontend\modules\app\models\FeedbackForm;

/**
 * 意见反馈
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class FeedbackController extends Controller {

    /**
     * {@inheritdoc}
     */
    public $modelClass = 'frontend\modules\app\models\FeedbackSceneSearch';


    /**
     * {@inheritdoc}
     */
    protected function verbs() {
        return [
            '*' => ['GET'],
            'create' => ['POST'],
        ];
    }

    /**
     * 问题与帮助分类列表
     * @inheritdoc
     */
    public function actionIndex() {
        /* @var $model \frontend\modules\app\models\FeedbackSceneSearch */
        $model = new $this->modelClass;
        return $model->search();
    }

    /**
     * 问题与帮助分类列表
     * @inheritdoc
     */
    public function actionView($id) {
        /* @var $model \frontend\modules\app\models\FeedbackSceneSearch */
        $model = new $this->modelClass;
        $model->parent_id = $id;
        return $model->search();
    }

    /**
     * 提交反馈内容
     * @return mixed
     */
    public function actionCreate() {
        $model = new FeedbackForm();
        $model->token = $this->token;
        if (!$model->load(Yii::$app->request->post(), '')) {
            return $model->dumpError('意见提交失败');
        }
        return $model->save();
    }

}
